﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RgUtility.OrmForOracle;
namespace RgUtility.OrmForOdbcConsoleTest
{

    class Program
    {
        static void Main(string[] args)
        {

            TestPage(); //Succeeded
            //TestMax();  //Succeeded
            //TestLike();//Succeeded
            //TestInsert(); //Succeeded
            //TextUpdate(); //Succeeded

        }
        public class A
        {
            public DateTime? Birthday { get; set; }
            public decimal Id { get; set; }
            public string Name { get; set; }
            public decimal? NUMBERTEST { get; set; }
        }
        static string connStr = "Data Source=orcl;user id=C##Test;password=test;";

        public static void TestMax()
        {
            using (var db = new RgUtility.OrmForOracle.DbContext(connStr))
            {
                var max = db.From<A>().Max(i => i.Id);

                //Console.WriteLine("test");
                //Assert.AreEqual(131, max);
            }
        }
        public static void TextUpdate()
        {
            using (var db = new RgUtility.OrmForOracle.DbContext(connStr))
            {
                var a = new A();
                a.Id = 1;
                a.Name = "fds";
                db.From<A>().Where(i => i.Id == a.Id).Update(a, i => new { i.Name });
            }
        }
        public static void TestInsert()
        {
            using (var db = new RgUtility.OrmForOracle.DbContext(connStr))
            {
                var a = new A();
                a.Id = 1;
                a.Name = "ccc";
                a.Birthday = DateTime.Now;
                var count = db.From<A>().Add(a, i => i);
            }
        }
        public static void TestPage()
        {
            using (var db = new DbContext(connStr))
            {
                var ls = db.From<A>().Select(i => i);
                var p = new Page(0, 1);
                var ls1 = db.From<A>().OrderBy(i => i.Id).Select(i => i, p);
            }
        }
        public static void TestLike()
        {
            using (var db = new DbContext(connStr))
            {
                var ls = db.From<A>().Where(i => i.Name.Contains("a")).Select(i => i);
                var ls1 = db.From<A>().Where(i => i.Id.Like("1")).Select(i => i);
                var ls2 = db.From<A>().Where(i => i.Name.Contains("a")).Select(i => i);
                var ls3 = db.From<A>().Where(i => i.Id.LikeStartWith("1")).Select(i => i);
                var ls4 = db.From<A>().Where(i => i.Id.LikeEndWith("1")).Select(i => i);
            }
        }
    }
}
